﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TA.DotNetUtils
{
	public class FNVHash64 : IHashGenerator<UInt64>, IHashGenerator<Int64>
	{
		#region PUBLIC
		#region METHODS
		public UInt64 Hash(byte[] data)
		{
			return this.Hash(data, FNVHash64.Basis);
		}
		public UInt64 Hash(byte[] data, UInt64 seed)
		{
			UInt64 hash = seed;
			foreach (byte b in data)
			{
				hash *= FNVHash64.Prime;
				hash ^= b;
			}
			return hash;
		}
		Int64 IHashGenerator<Int64>.Hash(byte[] data)
		{
			return (Int64)this.Hash(data, (UInt64)FNVHash64.Basis);
		}
		public Int64 Hash(byte[] data, Int64 seed)
		{
			return (Int64)this.Hash(data, (UInt64)seed);
		}
		#endregion
		#endregion
		#region INTERNAL
		#region CONST/STATIC
		const UInt64 Basis = 2166136261,
			Prime = 16777619;
		#endregion
		#endregion
	}
}
